import Mock from "mockjs";
const Random = Mock.Random;
interface DataList {
  date: string;
  name: string;
  address: string;
}

const DataList: DataList[] = [];
for (let i = 0; i < 100; i++) {
  DataList.push({
    date: Random.date(),
    name: Random.cname(),
    address: Random.county(true),
  });
}
Mock.mock("/api/list", "post", (params: any) => {
  let info = JSON.parse(params.body);
  let [index, size, total] = [info.current, info.pageSize, DataList.length];
  let len = total / size;
  let tatalPages =
    len - parseInt(String(len)) > 0 ? parseInt(String(len)) + 1 : len;
  let newDataList = DataList.slice((index - 1) * size, index * size);
  return {
    code: 200,
    message: "success",
    data: {
      current: index,
      pagesSize: size,
      rows: newDataList,
      total,
      totalPages: tatalPages,
    },
  };
});
